package com.adwin.addcoin.ui.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.adwin.addcoin.base.BaseDialog
import com.adwin.addcoin.databinding.DialogCoinsRewardBinding
import com.adwin.addcoin.utils.CacheDataManager
import com.adwin.addcoin.utils.installRepost
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import org.json.JSONObject

class CoinsRewardDialog(val mContext: Context,var coins:Long): BaseDialog(mContext) {

    lateinit var binding: DialogCoinsRewardBinding

    override fun getGravity(): Int = Gravity.CENTER

    override fun getWidth(): Int  = ViewGroup.LayoutParams.MATCH_PARENT

    override fun getHeight(): Int = ViewGroup.LayoutParams.MATCH_PARENT
    override fun initLayout(): View {
        binding = DialogCoinsRewardBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initData() {
        MainScope().launch (Dispatchers.IO){
            val json = JSONObject()
            json.put("coins","$coins")
            mContext.installRepost("showCoinsDialog",json)
        }
        binding.tvRewardCoins.text = "$coins"
        binding.tvCoinsButton.setOnClickListener {

            dismiss()
        }
    }
}